<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="net.groupme.gui.rendering.constants.RENDERING_CONSTANTS"%>
<%@page import="net.groupme.model.dao.DATABASE_CONSTANTS"%>
<%@page import="net.groupme.group.GroupListsManager"%>
<%@page import="java.util.List"%>
<%@page import="net.groupme.model.Group"%>
<%@page import="java.util.Iterator"%>
<%@page import="net.groupme.model.DashboardAnnouncement"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<title>GroupMe! - The Social Semantic Web [Home]</title>
	<!-- meta tags, link to css:  -->
	<%@ include file="./jsp-includes/metaheader.jsp" %>
	
	<!--  Ajax-Includes -->
    <script type='text/javascript' src='/GroupMe/dwr/interface/DWRUserManager.js'></script>
    <script type='text/javascript' src='/GroupMe/dwr/interface/DWRSearchManager.js'></script>
    <script type='text/javascript' src='./dwr/engine.js'></script>
	<script type='text/javascript' src='./dwr/util.js'> </script>
	<script src="./scriptaculous/prototype.js" type="text/javascript"></script>
	<script src="./scriptaculous/scriptaculous.js" type="text/javascript"></script>
    
    <script type="text/javascript" language="javascript">
    <!--//--><![CDATA[//><!--

     /**
      * Recomputes the User's Tag Cloud.
      */
     function computeTagCloud(){
     	$("tagCloudLoadingMessage").show();
     	DWRUserManager.getTagCloudForUser(null, null, showTagCloud);
     }
   		
	/**
	 * Visualize a tag cloud.
	 */
	 function showTagCloud(tagCloud){
	 	$("tagCloudLoadingMessage").hide();
	 	if(tagCloud == null || tagCloud.html == ""){
	 		$('tagcloud').innerHTML = "<i>You haven't used any tags!</i>";
	 	}else{
	 		$('tagcloud').innerHTML = tagCloud.html;
	 	}
	 }
	
	//init stuff:		
	function init() {
		//$("tagCloudLoadingMessage").hide();
		  DWRUtil.useLoadingMessage();
		  computeTagCloud();
		  <c:if test="${userManager.loggedIn}">
			  //DWRUserManager.getTagCloudForUser(null, null, showTagCloud);
		  </c:if>
		}

	//--><!]]>
    </script>
</head>
<body onload="init()">
	<!-- title image, logo:  -->
	<div id="header">
		<%@ include file="./jsp-includes/titleheader.jsp" %>
	</div>
	
	<!-- Menu: -->
	<div id="menu">
		<%@ include file="./jsp-includes/menu.jsp" %>
	</div>
	<!-- content and sidebar -->
	<div id="main">

		<!-- Sidebar -->
		<div id="sidebarLeft">
		<c:if test="${userManager.loggedIn}">
		<p><strong>Access your groups and resources:</strong> </p>
			<div id="tagcloud">
				
			</div>
			<span id="tagCloudLoadingMessage">
					<img src="<%= request.getContextPath() + RENDERING_CONSTANTS.RELATIVE_PATH_OF_AJAX_LOADING_IMAGE %>" alt="loading"/> 
					<small><i>refreshing tag cloud</i></small>
			</span>
			
		</c:if>
		</div>


		<!-- Content: -->
		<div id="mainBar">
		<c:choose>
			<c:when test="${userManager.loggedIn}">
				<h1>Your GroupMe! Home</h1>	
					
				<div id="personal-menu">
					<a href="<%=VIEW_VOCABULARY.RESTful_USER_URI_PATTERN + userManager.getUser().getUserName() %>" title="Your profile page...">you</a>
					| <a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_MYGROUPS %>" title="Groups you created...">your groups</a>
					| <a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_SUBSCRIPTIONS %>" title="Groups you subscribed to...">your subscriptions</a>
					| <a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_DASHBOARD %>" title="View what happened with your stuff...">your dashboard</a>
					| <a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_CREATE_NEW_GROUP %>" title="Create a new group...">create a new group</a>
					| <a href="<%= VIEW_VOCABULARY.ACTION_MODIFY_ACCOUNT %>" title="Modify your GroupMe! account...">account settings</a> 
				</div>
				
				<div id="mainGroupwindow">
						<% if((VIEW_VOCABULARY.VIEW_LATEST).equals(request.getParameter(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW))){ %>
							<%@include file="./jsp-includes/latestgroups.jsp"%>	
						<%}else if((VIEW_VOCABULARY.VIEW_SUBSCRIPTIONS).equals(request.getParameter(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW))){ %>
							<%@include file="./jsp-includes/subscriptions.jsp"%>
						<%}else if((VIEW_VOCABULARY.VIEW_DASHBOARD).equals(request.getParameter(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW))){ %>
							<%@include file="./jsp-includes/dashboard.jsp"%>
						<% } else if((VIEW_VOCABULARY.VIEW_SEARCH_RESULT).equals(request.getParameter(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW))){ %>
							<%@include file="./jsp-includes/mysearch.jsp"%>			
						<%}else if((VIEW_VOCABULARY.VIEW_CREATE_NEW_GROUP).equals(request.getParameter(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW))){ %>
							<%@include file="./jsp-includes/createNewGroup.jsp"%>			
						<%}else if((VIEW_VOCABULARY.VIEW_MYRESOURCE_QUEUE).equals(request.getParameter(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW))){ %>
							<%@include file="./jsp-includes/resourcequeue.jsp"%>			
						<%}else if((VIEW_VOCABULARY.VIEW_ADD_RESOURCE_FROM_MYRESOURCE_QUEUE_TO_A_GROUP).equals(request.getParameter(VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW))){ %>
							<%@include file="./jsp-includes/addResourceFromQueue.jsp"%>	
									
						<%}else{ %>			
							<%@include file="./jsp-includes/mygroups.jsp"%>	
						<%}%>
				</div>
				<br style="clear:right;" />
				
	 		</c:when>
			<c:otherwise>
				<h1>Your GroupMe! Home</h1>
				<p>Please login first! You do not have a GroupMe! account yet? Then quickly create one: 
					<a href="<%= VIEW_VOCABULARY.ACTION_REGISTRATION %>" title="Create a GroupMe! account">create account</a>
				</p>
				<p><strong>Login:</strong></p>
				<%@ include file="./jsp-includes/login.jsp" %>
			</c:otherwise>
		</c:choose>
		<br/>
		<div id="footer">
		<%@ include file="./jsp-includes/footer.jsp" %>
		</div>
			
		</div>
	</div>
	
	<!-- SidebarRight-->
		<div id="sidebarRight">
		<c:if test="${userManager.loggedIn}">
			<c:if test="${!userManager.queueOfUserEmpty}">
			<span style="color: gray; font-weight: lighter; font-size: small"><i>Resources you have not yet added to a group:</i></span>
			<div id="personalGroups0" class="smallGrouplist">
				<div class="smallGrouplistHead">
					<a href="<%= request.getContextPath() + "/" + VIEW_VOCABULARY.ACTION_HOME + "?" + VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW + "=" + VIEW_VOCABULARY.VIEW_MYRESOURCE_QUEUE %>">Resource Queue</a>
				</div>
				<c:forEach items="${userManager.latestResourcesOfQueue}" var="resource">
					<a href="<%= request.getContextPath() + "/" +  VIEW_VOCABULARY.ACTION_HOME + "?" + VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW + "=" + VIEW_VOCABULARY.VIEW_ADD_RESOURCE_FROM_MYRESOURCE_QUEUE_TO_A_GROUP + "&" + VIEW_VOCABULARY.PARAMETER_ID + "=" %><c:out value="${resource.id}"/>" title="Add resource to group(s)"><c:out value="${resource.name}"/></a><br/>
					<c:out value="${resource.description}"/><br/>
				</c:forEach>
			</div>
			</c:if>
			
			<span style="color: gray; font-weight: lighter; font-size: small"><i>Your latest GroupMe! groups and subscriptions:</i></span>
			<div id="personalGroups1" class="smallGrouplist">
				
				<div class="smallGrouplistHead">
					<a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_MYGROUPS %>">Your Groups</a>
				</div>
					<c:forEach items="${userManager.latestCreatedGroupsOfUser}" var="group">	
						<c:if test="${group.type != 'queue'}">
						<a href="<c:out value="${group.URL}"/>"><c:out value="${group.name}"/></a><br/>
						<c:out value="${group.description}"/><br/>
						</c:if>
					</c:forEach>
				<div class="smallGrouplistFooter"><a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_MYGROUPS %>">more... </a></div>
			</div>
<!--
			<div id="personalGroups2" class="smallGrouplist">
				<div class="smallGrouplistHead">
					Your most visited Groups
				</div>
					- coming soon -
				<div class="smallGrouplistFooter"><a target="_blank" href="./">more... </a></div>
			</div>
-->	
			<div id="personalGroups3" class="smallGrouplist">
				<div class="smallGrouplistHead">
					<a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_SUBSCRIPTIONS %>">Your Subscriptions</a>
				</div>
				<c:if test="${!userManager.subscriber}">- You have no subcriptions -</c:if>
					<c:forEach items="${userManager.latestSubscribedGroupsOfUser}" var="group" varStatus="status">	
						<a href="<c:out value="${group.URL}"/>"><c:out value="${group.name}"/></a><br/>
						<c:out value="${group.description}"/><br/>
					</c:forEach>
				<div class="smallGrouplistFooter"><a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_SUBSCRIPTIONS %>">more... </a></div>
			</div>
			<div id="personalGroups4" class="smallGrouplist">
				<div class="smallGrouplistHead">
					<a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_DASHBOARD %>">Your Dashboard</a>
				</div>
				<% 	List<DashboardAnnouncement> ann = userManager.getLatest5DashboardAnnouncements(); %>
				<% 	Iterator<DashboardAnnouncement> it = ann.iterator(); %>
				<% 	DashboardAnnouncement da = new DashboardAnnouncement(); 
					if(!it.hasNext()){%>
					- No news for you yet -
				<% 	}
					while (it.hasNext()) { 
						da = it.next(); %>
						<strong><%=da.getDate()%> -</strong>
						<% if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_CREATED.equals(da.getAction())){%>
						<strong>New Group created</strong></br>
						<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_DELETED.equals(da.getAction())){%>
						<strong>Group deleted</strong></br>
						<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_SUBSCRIBED.equals(da.getAction())){%>
						<strong>Group was subscribed</strong></br>
						<a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_USER%>/<%=da.getUserId()%>">User</a> subscribed to your
						<a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_GROUP %>/<%=da.getGroupId()%>">Group</a>.
						<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_UNSUBSCRIBED.equals(da.getAction())){%>
						<strong>Group was unsubscribed</strong></br>
						<a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_USER%>/<%=da.getUserId()%>">User</a> unsubscribed your
						<a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_GROUP %>/<%=da.getGroupId()%>">Group</a>.
						<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_GROUP_TAGGED.equals(da.getAction())){%>
						<strong>Group was tagged</strong></br>
						Your <%if (MODEL_CONSTANTS.ROLE_SUBSCRIBER.equals(da.getRole())){ %> subscribed <%} %> 
						<a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_GROUP %>/<%=da.getGroupId()%>">Group</a>
						was tagged.
						<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_RESOURCE_CREATED.equals(da.getAction())){%>
						<strong>New Resource created</strong></br>
						A new <a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_RESOURCE %>/<%=da.getResourceId()%>">Resource</a> was added to your subscribed
						<a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_GROUP %>/<%=da.getGroupId()%>">Group</a>.
						<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_RESOURCE_REMOVED.equals(da.getAction())){%>
						<strong>Resource removed</strong></br>
						The <a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_RESOURCE %>/<%=da.getResourceId()%>">Resource</a> was removed from your subscribed
						<a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_GROUP %>/<%=da.getGroupId()%>">Group</a>.
						<%} else if (DATABASE_CONSTANTS.TABLE_LOG_EVENT_ACTION_RESOURCE_TAGGED.equals(da.getAction())){%>
						<strong>Resource tagged</strong></br>
						A <a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_RESOURCE %>/<%=da.getResourceId()%>">Resource</a> in your 
						<%if (MODEL_CONSTANTS.ROLE_SUBSCRIBER.equals(da.getRole())){ %> subscribed <%} %> <a href="./<%=VIEW_VOCABULARY.REQUEST_TYPE_GROUP %>/<%=da.getGroupId()%>">Group</a>
						was tagged.
						<%} 
						if(it.hasNext()) {%><br/><%} %>
				<%}  %>
				<div class="smallGrouplistFooter"><a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_DASHBOARD %>">more... </a></div>
			</div>
		</c:if>
		<% GroupListsManager glma = new GroupListsManager(); %>
		<span style="color: gray; font-weight: lighter; font-size: small"><i>What's happening in the GroupMe! world?</i></span>
		<div id="globalGroups1" class="smallGrouplist">
			<div class="smallGrouplistHead">
				<a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_LATEST %>">Latest Groups</a>
			</div>
			<% List<Group> latestg = glma.get5LatestGroups();
			Iterator<Group> ite = latestg.iterator();
			while (ite.hasNext()){
				Group actualGroup = ite.next(); %>
				<a href="<%= actualGroup.getURL().toString() %>"><%= actualGroup.getName() %></a><br/>
			<% }; %>
			<div class="smallGrouplistFooter"><a href="./<%=VIEW_VOCABULARY.ACTION_HOME%>?<%=VIEW_VOCABULARY.PARAMETER_MYHOME_VIEW %>=<%=VIEW_VOCABULARY.VIEW_LATEST %>">more... </a></div>
		</div>
<!--	
		<div id="globalGroups2" class="smallGrouplist">
			<div class="smallGrouplistHead">
				Most Popular Groups
			</div>
				- coming soon -
			<div class="smallGrouplistFooter"><a target="_blank" href="./">more... </a></div>
		</div>
-->
	</div>
	
</body>
</html>